package com.example.bailin.giftsay.sort.activity;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.baseclass.BaseActivity;
import com.example.bailin.giftsay.entity.SelectGiftEntity;
import com.example.bailin.giftsay.main.adapter.ShowAllAdapter;
import com.example.bailin.giftsay.tool.MyApp;
import com.example.bailin.giftsay.tool.NetTool;
import com.example.bailin.giftsay.tool.UrlProvide;

/**
 * Created by bailin on 16/8/25.
 */
public class DPSkipActivity extends BaseActivity implements View.OnClickListener {

    private TextView tv;
    private ImageView iv;
    private RecyclerView rv;

    @Override
    protected int setLayout() {
        return R.layout.activity_dpskip;
    }

    @Override
    protected void initView() {
        tv = bindView(R.id.tv_dpskip_title);
        iv = bindView(R.id.iv_dpskip_return);
        rv = bindView(R.id.rv_dpskip_id);
        iv.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        String title = intent.getStringExtra("title");
        tv.setText(title);

        tool().getData(UrlProvide.PRODUCT_ALL + url + UrlProvide.PRODUCT_ALL1, SelectGiftEntity.class, new NetTool.NetInterface<SelectGiftEntity>() {
            @Override
            public void onSuccess(SelectGiftEntity selectGiftEntity) {
                ShowAllAdapter adapter = new ShowAllAdapter();
                GridLayoutManager manager = new GridLayoutManager(MyApp.getContext(), 2);
                adapter.setEntity(selectGiftEntity);
                rv.setLayoutManager(manager);
                rv.setAdapter(adapter);
            }

            @Override
            public void onError(String errorMsg) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_dpskip_return:
                finish();
                break;
        }
    }
}
